
<style lang="less">
	page{
		background-color: #F7F7F7;
	}
	.main{
	}
	.main-top{
	 display: flex;
	 justify-content: center;
	 align-items: center;
	 margin-top: 80upx;
	 .main-top-fl{
		 font-size: 30upx;
		 color: #333333;
		 line-height: 36upx;
		 border: 1upx solid #DDDDDD;
		 border-radius: 17upx;
		 padding: 50upx 20upx;
		 box-sizing: border-box;
		 background: #FFFFFF;
	 }
	 .main-top-img{
		 width: 50upx;
		 margin: 0 50upx;
	 }
	}
	  
	  .withdraw{
	    margin-top: 80upx;
	    padding: 30upx;
	    box-sizing: border-box;
	    background: #ffffff;
	    .withdraw_title{
	      font-size:28upx;
	      color:rgba(51,51,51,1);
	      line-height:34upx;
	    }
	    .withdraw-top{
	      display: flex;
	      justify-content: space-between;
	      .withdraw-top-fl{
	        font-size:28upx;
	        color:rgba(51,51,51,1);
	        line-height:34upx;
	      }
	      .withdraw-top-fr{
	        font-size:24upx;
	        font-weight:500;
	        color:rgba(153,153,153,1);
	        line-height:34upx;
	      }
	    }
	   }
	  .withdraw_l{
	    font-family:'DINCond';
	    overflow: hidden;
	    font-size:46upx;
	    color:rgba(51,51,51,1);
	    line-height:55upx;
	    padding: 40upx 0;
	    display: flex;
		align-items: center;
		border-bottom: 1upx solid #EDEDED;
	   view{
	     line-height:55upx;
	     font-size:40upx;
	   }
	   input{
	     margin-left: 20upx;
	    line-height:55upx;
	    display: block;
	    height: 55upx;
	    font-size:40upx;
	    outline: none;
	   }
	  }
	  .withdraw_r{
		margin-top: 10upx;
		display: flex;
		align-items: center;
		.withdraw_r-text{
			font-size: 24upx;
			color: #333333;
			line-height: 29px;
		}
		.withdraw_r-jine{
			font-size: 24upx;
			font-family: 'DINCond';
			font-weight: 400;
			color: #E93246;
			margin-left: 10upx;
		}
	    .mony{
	      margin-left: 20upx;
		  font-size: 24upx;
		  font-weight: 500;
		  color: #2E93D5;
		  padding: 0 20upx;
		  box-sizing: border-box;
	    }
	   }
	  .withdraw_msg{
	    background:rgba(247,247,247,1);
	    border:1px solid rgba(237,237,237,1);
	    border-radius:4upx;
	    font-size:24upx;
	    color:rgba(153,153,153,1);
	    line-height:34upx;
	    padding: 25upx 30upx;
	    margin-top: 20upx;
	   }
	   .placeholder{
	     color: #dddddd;
	   }
	  
	   .button-large-wrap{
	     margin: 65upx auto 0;
	     background: rgba(7,5,6,1);
	     width: 690upx;
	     height: 90upx;
	     font-size: 30upx;
	     color: #ffffff;
	     text-align: center;
	     line-height: 90upx;
	     border-radius: 10upx;
	   }
	   .button-tibs{
		   font-size: 22upx;
		   font-weight: 500;
		   color: #999999;
		   line-height: 30upx;
		   margin-top: 10upx;
		   text-align: center;
	   }
</style>


<template>

	<view>
		<view class="main">
			<view class="main-top">
				<view class="main-top-fl" v-if="type==1">收益账户</view>
				<view class="main-top-fl" v-else-if="type==2">充值余额</view>
				<view class="main-top-fl" v-else-if="type==3">营销账户</view>
				<image src="https://static.xpandago.net/wechat/images/jiantou-Img.png"  class="main-top-img" mode="widthFix"/>
				<view class="main-top-fl" v-if="type==1 || type==2">营销账户</view>
				<view class="main-top-fl" v-else-if="type==3">充值余额</view>
			</view>
			  <view class="withdraw">
			    <view class="withdraw_title">{{zhuanruTxte}}</view>
			    <view class="withdraw_l">
			      <view>¥</view>
				  <input type="digit" :value="balance"  maxlength="11" @input="changvalue"  :placeholder="shuruTxte" placeholder-class="placeholder" />
			    </view>
			    <view class="withdraw_r">
			      <view class="withdraw_r-text">{{kezhuanTxte}}</view>
				  <view class="withdraw_r-jine">¥{{mony}}</view>
			      <view class="mony" @tap="allwithdraw">{{allTxte}}</view>
			    </view>
			  </view>
			  <view class="button-large-wrap" @tap="quding">{{quedingTxte}}</view>
			  <view class="button-tibs" v-if="type!=3">*该资金将用于店铺运营，如: 发放店铺优惠券等</view>
		</view>
	</view>

</template>

<script>
	import api from '@/common/api';
  export default {

    components: {},

    data () {

      return {
		  token: '',
		  balance:'',
		  zhuanruTxte:'转入金额',
		  shuruTxte:'请输入转入金额',
		  kezhuanTxte:'可转入金额',
		  quedingTxte:'确定转入',
		  allTxte:'全部转入',
		  mony:0,
		  type:1, //1收益账户2充值余额3转出
	  }
    },
	onLoad(options) {
		if(options.type != '' && options.type != null && options.type != undefined){
			this.type = options.type
			if(options.type==1 || options.type==2){
				this.quedingTxte='确定转入'
				this.kezhuanTxte='可转入金额'
				this.shuruTxte='请输入转入金额'
				this.zhuanruTxte='转入金额'
				this.allTxte='全部转入'
			}else if(options.type==3){
				this.quedingTxte='确定转出'
				this.kezhuanTxte='可转出金额'
				this.shuruTxte='请输入转出金额'
				this.zhuanruTxte='转出金额'
				this.allTxte='全部转出'
			}
			this.mony=options.mony
		}
		this.token = uni.getStorageSync('token')
	},
    methods: {
		tapShow(){
			this.hidden = true;
		},
		//输入
		changvalue(e){
			this.balance=e.detail.value
		},
		allwithdraw(){
			this.balance=this.mony
		},
		//关闭弹窗
		closeModel(){
		 this.hidden = false;
		},
		quding(){
			if(this.type==1 || this.type==2){
				this.tomarketing()
			}else if(this.type==3){
				this.outmarketing()
			}
		},
		//转出接口
		async outmarketing(){
			if(this.balance=='' || this.balance==null){
				uni.showToast({
					title: '请输入正确的转出金额',
					icon: 'none'
				})
				return false
			}
			const [err, res] = await api.outmarketing({
				query: {
					price: this.balance
				},
				header:{
					'Content-Type': 'application/x-www-form-urlencoded',
					'token':this.token
				},
				method:'POST'
			 });
			 if(res.data.code == 0){
				 uni.showToast({
				 	title: res.data.msg,
				 	icon: 'none'
				 })
				 setTimeout(() =>{
					 uni.navigateBack()
				 },600)
			 }else{
				 uni.showToast({
				 	title: res.data.msg,
				 	icon: 'none'
				 })
			 }
		},
		//转入接口
		async tomarketing(){
			if(this.balance=='' || this.balance==null){
				uni.showToast({
					title: '请输入正确的转入金额',
					icon: 'none'
				})
				return false
			}
			const [err, res] = await api.tomarketing({
				query: {
					moneyType: this.type,
					price: this.balance
				},
				header:{
					'Content-Type': 'application/x-www-form-urlencoded',
					'token':this.token
				},
				method:'POST'
			 });
			 if(res.data.code == 0){
				 uni.showToast({
				 	title: res.data.msg,
				 	icon: 'none'
				 })
				 setTimeout(() =>{
					 uni.navigateBack()
				 },600)
			 }else{
				 uni.showToast({
				 	title: res.data.msg,
				 	icon: 'none'
				 })
			 }
		}
	}
  }
</script>